﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================

using System;
using System.Collections.Generic;

namespace Caffeine.Core.Test.TestModel.PropertyRegistrations
{
    public class ModelForComputedPropertyTest : ModelBase
    {
        private readonly ModelProperty<Int32> _intPropertyA;
        private readonly ModelProperty<Int32> _intPropertyB;
        private readonly ModelProperty<Nullable<Double>> _doublePropertyA;
        private readonly ModelProperty<Nullable<Double>> _doublePropertyB;
        private readonly ModelProperty<String> _stringPropertyA;
        private readonly ModelProperty<String> _stringPropertyB;
        private readonly ModelProperty<Object> _objectPropertyA;
        private readonly ModelProperty<Object> _objectPropertyB;

        public ModelForComputedPropertyTest()
        {
            _intPropertyA = RegisterProperty<Int32>("IntPropertyA");
            _intPropertyB = RegisterComputedProperty<Int32>("IntPropertyB", ComputeIntProperty, IntPropertyA);
            _doublePropertyA = RegisterProperty<Nullable<Double>>("DoublePropertyA");
            _doublePropertyB = RegisterComputedProperty<Nullable<Double>>("DoublePropertyB", ComputeDoubleProperty, DoublePropertyA);
            _stringPropertyA = RegisterProperty<String>("StringPropertyA");
            _stringPropertyB = RegisterComputedProperty<String>("StringPropertyB", ComputeStringProperty, StringPropertyA);
            _objectPropertyA = RegisterProperty<Object>("ObjectPropertyA");
            _objectPropertyB = RegisterComputedProperty<Object>("ObjectPropertyB", ComputeObjectProperty, ObjectPropertyA);
        }

        public ModelProperty<Int32> IntPropertyA
        {
            get
            {
                return _intPropertyA;
            }
        }

        public ModelProperty<Int32> IntPropertyB
        {
            get
            {
                return _intPropertyB;
            }
        }

        public ModelProperty<Nullable<Double>> DoublePropertyA
        {
            get
            {
                return _doublePropertyA;
            }
        }

        public ModelProperty<Nullable<Double>> DoublePropertyB
        {
            get
            {
                return _doublePropertyB;
            }
        }

        public ModelProperty<String> StringPropertyA
        {
            get
            {
                return _stringPropertyA;
            }
        }

        public ModelProperty<String> StringPropertyB
        {
            get
            {
                return _stringPropertyB;
            }
        }

        public ModelProperty<Object> ObjectPropertyA
        {
            get
            {
                return _objectPropertyA;
            }
        }

        public ModelProperty<Object> ObjectPropertyB
        {
            get
            {
                return _objectPropertyB;
            }
        }

        private static Int32 ComputeIntProperty(IEnumerable<ModelProperty<Int32>> properties, Int32 newPropertyValue)
        {
            return newPropertyValue;
        }

        private static Nullable<Double> ComputeDoubleProperty(IEnumerable<ModelProperty<Nullable<Double>>> properties, Nullable<Double> newPropertyValue)
        {
            return newPropertyValue;
        }

        private static String ComputeStringProperty(IEnumerable<ModelProperty<String>> properties, String newPropertyValue)
        {
            return newPropertyValue;
        }

        private static Object ComputeObjectProperty(IEnumerable<ModelProperty<Object>> properties, Object newPropertyValue)
        {
            return newPropertyValue;
        }
    }
}
